package com.ruoyi.project.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.project.domain.ProjectApplication;
import com.ruoyi.project.service.IProjectApplicationService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 申报项目Controller
 * 
 * @author czj
 * @date 2025-01-06
 */
@RestController
@RequestMapping("/application")
public class ProjectApplicationController extends BaseController
{
    @Autowired
    private IProjectApplicationService projectApplicationService;

    /**
     * 查询申报项目列表
     */
    @RequiresPermissions("project:application:list")
    @GetMapping("/list")
    public TableDataInfo list(ProjectApplication projectApplication)
    {
        startPage();
        List<ProjectApplication> list = projectApplicationService.selectProjectApplicationList(projectApplication);
        return getDataTable(list);
    }

    /**
     * 导出申报项目列表
     */
    @RequiresPermissions("project:application:export")
    @Log(title = "申报项目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProjectApplication projectApplication)
    {
        List<ProjectApplication> list = projectApplicationService.selectProjectApplicationList(projectApplication);
        ExcelUtil<ProjectApplication> util = new ExcelUtil<ProjectApplication>(ProjectApplication.class);
        util.exportExcel(response, list, "申报项目数据");
    }

    /**
     * 获取申报项目详细信息
     */
    @RequiresPermissions("project:application:query")
    @GetMapping(value = "/{applicationId}")
    public AjaxResult getInfo(@PathVariable("applicationId") Long applicationId)
    {
        return success(projectApplicationService.selectProjectApplicationByApplicationId(applicationId));
    }

    /**
     * 新增申报项目
     */
    @RequiresPermissions("project:application:add")
    @Log(title = "申报项目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProjectApplication projectApplication)
    {
        return toAjax(projectApplicationService.insertProjectApplication(projectApplication));
    }

    /**
     * 修改申报项目
     */
    @RequiresPermissions("project:application:edit")
    @Log(title = "申报项目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProjectApplication projectApplication)
    {
        return toAjax(projectApplicationService.updateProjectApplication(projectApplication));
    }

    /**
     * 删除申报项目
     */
    @RequiresPermissions("project:application:remove")
    @Log(title = "申报项目", businessType = BusinessType.DELETE)
	@DeleteMapping("/{applicationIds}")
    public AjaxResult remove(@PathVariable Long[] applicationIds)
    {
        return toAjax(projectApplicationService.deleteProjectApplicationByApplicationIds(applicationIds));
    }
}
